// HSS.Forms.DetailModuleChildBase.cs
// ----------------------------------------------------------------------------
// Licensed under the MIT license
// http://www.opensource.org/licenses/mit-license.html
// ----------------------------------------------------------------------------
// HighSpeed-Solutions, LLC
// Copyright (c) 2001-2010
// ----------------------------------------------------------------------------
// File:       DetailModuleChildBase.cs
// Author:     HSS\gbanta
// Created:    08/12/2010
// Modified:   12/04/2010
// ----------------------------------------------------------------------------
namespace HSS.Forms
{
	#region Using Directives
	using System;
	using System.ComponentModel;

	using HSS.Data;
	#endregion

	#region DetailModuleChildBase
	/// <summary>
	/// Summary description for FormDetailImpl.
	/// </summary>
	[DefaultEvent("Dirty")]
	[DefaultProperty("UniqueID")]
	[ToolboxItem(false)]
	public partial class DetailModuleChildBase : ModuleBase
	{
		/// <summary>
		/// ctor
		/// </summary>
		public DetailModuleChildBase()
		{
			// This call is required by the Windows.Forms Form Designer.
			InitializeComponent();
		}

		#region Properties
		/// <summary>
		/// Indicates if this formhas been loaded
		/// </summary>
		[Description("Indicates if this form has been loaded.")]
		[Browsable(false)]
		public bool Loaded
		{
			get { return _loaded; }
			set { _loaded = value; }
		} bool _loaded = false;
		/// <summary>
		/// Indicates if this form is currently loading
		/// </summary>
		[Description("Indicates if this form is currently loading.")]
		[Browsable(false)]
		public bool Loading
		{
			get { return _loading; }
			set { _loading = value; }
		} bool _loading = false;
		/// <summary>
		/// Indicates if this form is currently updating
		/// </summary>
		[Description("Indicates if this form is currently updating.")]
		[Browsable(false)]
		public bool Updating
		{
			get { return _updating; }
			set { _updating = value; }
		} bool _updating = false;
		/// <summary>
		/// Contains the detail data for this form
		/// </summary>
		[Description("Contains the detail data for this form.")]
		[Browsable(false)]
		public IDataContainer DetailData
		{
			get { return _detailData; }
			set { _detailData = value; }
		} IDataContainer _detailData;
		/// <summary>
		/// The current Action of this form
		/// </summary>
		[Description("The current Action of this form.")]
		[Browsable(false)]
		public ModuleActions CurrentAction
		{
			get { return _CurrentAction; }
			set
			{
				_CurrentAction = value;
				if (null != this.StatusChanged)
					this.StatusChanged(this, EventArgs.Empty);
			}
		} ModuleActions _CurrentAction;
		/// <summary>
		/// The Primary KEY for the data currently loaded in the Module
		/// </summary>
		[Description("The Primary KEY for the data currently loaded in the Module.")]
		[Browsable(false)]
		public string UniqueID
		{
			get { return _uniqueID; }
			set { _uniqueID = value; }
		} string _uniqueID = "-1";
		#endregion

		#region Methods
		/// <summary>
		/// Virtual Method for the getting the data from the detail form
		/// </summary>
		/// <returns>IDataContainer</returns>
		public virtual IDataContainer GetData() { return null; }
		/// <summary>
		/// Virtual Method for the reseting the detail form
		/// </summary>
		public virtual void Reset() { }
		/// <summary>
		/// Virtual Method for the loading data into the detail form
		/// </summary>
		/// <param name="Data"></param>
		public virtual void LoadData(IDataContainer Data) { }
		/// <summary>
		/// Virtual Method for the loading the lookups
		/// </summary>
		public virtual void LoadLookup(bool PreserveSelectValue) { }
		/// <summary>
		/// Validate date before saving
		/// </summary>
		/// <returns>Boolean indicating if Data is valid</returns>
		public virtual bool ValidateData(ref string ErrorMessage) { return true; }
		/// <summary>
		/// Set Module to a Dirty State
		/// </summary>
		public virtual void SetDirty()
		{
			this.SetDirty(true);
		}
		/// <summary>
		/// Set Module to a Dirty State
		/// </summary>
		/// <param name="IsEditing">Indicates user has begun editing fields</param>
		public virtual void SetDirty(bool IsEditing)
		{
			this.SetDirty(false, IsEditing, null);
		}
		/// <summary>
		/// Set Module to a Dirty State
		/// </summary>
		/// <param name="ForceDirty">Force setting Module to dirty and raise event.</param>
		/// <param name="IsEditing">Indicates user has begun editing fields</param>
		public virtual void SetDirty(bool ForceDirty, bool IsEditing)
		{
			this.SetDirty(ForceDirty, IsEditing, null);
		}
		/// <summary>
		/// Set Module to a Dirty State
		/// </summary>
		/// <param name="ForceDirty">Force setting Module to dirty and raise event.</param>
		/// <param name="IsEditing">Indicates user has begun editing fields</param>
		/// <param name="State">State object</param>
		public virtual void SetDirty(bool ForceDirty, bool IsEditing, object State)
		{
			if (!this.IsDirty | ForceDirty)
				this.IsDirty = true;
			InvokeDirty(this, new DirtyEventArgs(this.IsDirty, IsEditing, State));
		}
		/// <summary>
		/// Set Modules Dirty State
		/// </summary>
		/// <param name="IsDirty">Indicates if form is dirty</param>
		/// <param name="State">State object</param>
		public virtual void SetDirty(bool IsDirty, object State)
		{
			this.IsDirty = IsDirty;
			InvokeDirty(this, new DirtyEventArgs(IsDirty, true, State));
		}
		#endregion

		#region Events
		/// <summary>
		/// StateChanged Event
		/// </summary>
		public event EventHandler StatusChanged;
		#endregion
	}
	#endregion
}